package com.qinsoft.business.onsalelog.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;

import com.qinsoft.business.onsalelog.bean.OnSaleLog;
import com.qinsoft.frame.messages.WriteMessage;
import com.qinsoft.frame.utils.DbUtil;


public class OnSaleLogDao
{

    public void save(OnSaleLog log)
    {
        SqlSession sqlMap = null;
        try
        {
            //获取连接对象
            sqlMap = DbUtil.getSqlMapClient();
            //执行保存方法
            sqlMap.insert("com.qinsoft.business.onsalelog.sqlMap.onsalelog.insert", log);
        }
        catch (Exception e)
        {
            WriteMessage.WriteErrorLog(this.getClass().toString() + ".save(" + log.getNick() + ")", e);
        }
        finally
        {
            sqlMap.close();
        }
    }
    
    public List<OnSaleLog> select(String nick)
    {
        SqlSession sqlMap = null;
        List<OnSaleLog> list = new ArrayList<OnSaleLog>();
        try
        {
            //获取连接对象
            sqlMap = DbUtil.getSqlMapClient();
            //执行查询方法
            list = sqlMap.selectList("com.qinsoft.business.onsalelog.sqlMap.onsalelog.selectWeek", nick);
        }
        catch (Exception e)
        {
            WriteMessage.WriteErrorLog(this.getClass().toString() + ".select(" + nick + ")", e);
        }
        finally
        {
            sqlMap.close();
        }
        return list;
    }
    
    public List<OnSaleLog> selectAll(String nick, Long begin){
        SqlSession sqlMap = null;
        List<OnSaleLog> list = new ArrayList<OnSaleLog>();
        try
        {
            //获取连接对象
            sqlMap = DbUtil.getSqlMapClient();
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("begin", begin);
            param.put("nick", nick);
            //执行查询方法
            list = sqlMap.selectList("com.qinsoft.business.onsalelog.sqlMap.onsalelog.selectAll", param);
        }
        catch (Exception e)
        {
            WriteMessage.WriteErrorLog(this.getClass().toString() + ".selectAll(" + nick + ")", e);
        }
        finally
        {
            sqlMap.close();
        }
        return list;
    }
    
    public Long count(String nick){
        SqlSession sqlMap = null;
        try
        {
            //获取连接对象
            sqlMap = DbUtil.getSqlMapClient();
            //执行查询方法
            return sqlMap.selectOne("com.qinsoft.business.onsalelog.sqlMap.onsalelog.count", nick);
        }
        catch (Exception e)
        {
            WriteMessage.WriteErrorLog(this.getClass().toString() + ".count(" + nick + ")", e);
        }
        finally
        {
            sqlMap.close();
        }
        return 0L;
    }
}
